
#include "test1.h"

void tenacitas::text_log_file::test1::wcnl( const log::level & p_level,
                                  logger & p_log,
				  const char * p_func,
                                  const char * p_file,				  
                                  int64_t p_line ) {
    std::cout << "Can not log for level '"
              << p_level.str( )
              << "', because current level is '"
              << p_log.get_level( ).str( )
              << "', in "
              << p_file << ", "
              << p_func << ", "
              << p_line << std::endl;
}

void tenacitas::text_log_file::test1::f0( ) {
    try {
        logger l_log;

        if ( l_log.can_log( log::level::debug ) ) {
            log_debug( l_log ) << "logging in 'f0'!!!";
        }
        else {
            wcnl( log::level::debug, l_log, __func__, __FILE__, __LINE__ );
        }
        
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "000 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

void tenacitas::text_log_file::test1::f1( ) {
    try {
        logger l_log;
        
        if ( l_log.can_log( log::level::error ) ) {
            log_error( l_log ) << "hello " << 998;
        }
        else {
            wcnl( log::level::error, l_log, __func__, __FILE__, __LINE__ );
        }

        if ( l_log.can_log( log::level::trace ) ) {
            log_trace( l_log ) << "new line?";
        }
        else {
            wcnl( log::level::trace, l_log, __func__, __FILE__, __LINE__ );
        }

	
        if ( l_log.can_log( log::level::info ) ) {
            log_info( l_log ) << "not yet";
        }
        else {
            wcnl( log::level::info, l_log, __func__, __FILE__, __LINE__ );
        }
	
        if ( l_log.can_log( log::level::trace ) ) {
            log_trace( l_log ) << "counting: " << 1 << ", " << 2 << ", " << 3;
        }
        else {
            wcnl( log::level::trace, l_log, __func__, __FILE__, __LINE__ );
        }


        f0( );
    }
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "010 exception: '" << l_ex.what( ) << "'" << std::endl;
    }    
        
}


void tenacitas::text_log_file::test1::f2( ) {
    try {
        logger l_log;
        
        if ( l_log.can_log( log::level::warn ) ) {
            log_warn( l_log ) << "how are you doing?";
        }
        else {
            wcnl( log::level::warn, l_log, __func__, __FILE__, __LINE__ );
        }
	
        if ( l_log.can_log( log::level::trace ) ) {
            log_trace( l_log ) << "just fine";
        }
        else {
            wcnl( log::level::trace, l_log, __func__, __FILE__, __LINE__ );
        }

        f0( );

        log_critical( l_log ) << "ouch";
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "020 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

void tenacitas::text_log_file::test1::f3( ) {
    try {
        logger l_log;
        
        if ( l_log.can_log( log::level::debug ) ) {
            log_debug( l_log ) << "logging in 'f3'";
        }
        else {
            wcnl( log::level::debug, l_log, __func__, __FILE__, __LINE__ );
        }        
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "030 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

void tenacitas::text_log_file::test1::f4( ) {
    try {
        logger l_log;

        l_log.set_level( log::level::trace );
        
        if ( l_log.can_log( log::level::debug ) ) {
            log_debug( l_log ) << "logging in 'f4'!!!";
        }
        else {
            wcnl( log::level::debug, l_log, __func__, __FILE__, __LINE__ );
        }                
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "040 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

void tenacitas::text_log_file::test1::f5( ) {
    try {
        logger l_log;
        
        if ( l_log.can_log( log::level::warn ) ) {
            log_warn( l_log ) << "logging in 'f5'!!!";
        }
        else {
            wcnl( log::level::warn, l_log, __func__, __FILE__, __LINE__ );
        }        
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "050 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}


void tenacitas::text_log_file::test1::f6( ) {
    try {
        logger l_log;
        
        if ( l_log.can_log( log::level::debug ) ) {
            log_debug( l_log ) << "logging in 'f6'!!!";
        }
        else {
            wcnl( log::level::debug, l_log, __func__, __FILE__, __LINE__ );
        }        
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "060 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

void tenacitas::text_log_file::test1::f7( ) {
    try {
        logger l_log;
        
        if ( l_log.can_log( log::level::warn ) ) {
            log_warn( l_log ) << "logging in 'f7'!!!";
        }
        else {
            wcnl( log::level::warn, l_log, __func__, __FILE__, __LINE__ );
        }
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "070 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}
 
void tenacitas::text_log_file::test1::f8( ) {
    try {
        logger::set_level_all( log::level::trace );

        logger l_log;
        
        if ( l_log.can_log( log::level::debug ) ) {
            log_debug( l_log ) << "logging in 'f8'!!!";
        }
        else {
            wcnl( log::level::debug, l_log, __func__, __FILE__, __LINE__ );
        }
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "080 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

// void tenacitas::text_log_file::test1::f9( ) {
//     try {
//         logger l_log;
//         logger l_log_1( l_log );
//     }    
//     catch ( tenacitas::exception::exception & l_ex ) {
//         std::cout << "exception: '" << l_ex.what( ) << "'" << std::endl;
//     }
// }

// void tenacitas::text_log_file::test1::f10( ) {
//     try {
//         logger l_log;
//         logger l_log_1( std::move( l_log ) );
//     }    
//     catch ( tenacitas::exception::exception & l_ex ) {
//         std::cout << "exception: '" << l_ex.what( ) << "'" << std::endl;
//     }
// }

// void tenacitas::text_log_file::test1::f11( ) {
//     try {
//         logger l_log;
//         logger l_log_1 = l_log;
//     }    
//     catch ( tenacitas::exception::exception & l_ex ) {
//         std::cout << "exception: '" << l_ex.what( ) << "'" << std::endl;
//     }
// }


void tenacitas::text_log_file::test1::f12( ) {
    try {
        logger l_log;
        logger && l_log_1 = std::move( l_log );
        log_error( l_log_1 ) << "logging in 'f12'!!!";
        f13( std::move( l_log_1 ) );        
    }    
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "090 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

void tenacitas::text_log_file::test1::f13( logger && p_log ) {
    log_error( p_log ) << "logging in 'f13'!!!";
}

void tenacitas::text_log_file::test1::f14( logger & p_log ) {
    try {
        log_error( p_log ) << "logging in 'f14'!!!";
    }
    catch ( tenacitas::exception::exception & l_ex ) {
        std::cout << "095 exception: '" << l_ex.what( ) << "'" << std::endl;
    }
}

// void tenacitas::text_log_file::test1::f15( ) {
//     try {
//         logger l_log;

//         logger * l_log_ptr = & l_log;
        
        
//         logger::set_level( log::level::trace );
        
//         if ( l_log_1->can_log( log::level::debug ) ) {
//             log_debug( *l_log_1 ) << "logging in 'f15'!!!";
//         }
//         else {
//             wcnl( log::level::debug, ( *l_log_1 ), __func__, __FILE__, __LINE__ );
//         }
//     }    
//     catch ( tenacitas::exception::exception & l_ex ) {
//         std::cout << "exception: '" << l_ex.what( ) << "'" << std::endl;
//     }
// }

// void tenacitas::text_log_file::test1::f16( ) {
//     try {
//         logger * l_log = new logger( );
        
//         logger::set_level( log::level::trace );
        
//         if ( l_log->can_log( log::level::debug ) ) {
//             log_debug( ( *l_log ) ) << "logging in 'f16'!!!";
//         }
//         else {
//             wcnl( log::level::debug, ( *l_log ), __func__, __FILE__, __LINE__ );
//         }
//     }    
//     catch ( tenacitas::exception::exception & l_ex ) {
//         std::cout << "exception: '" << l_ex.what( ) << "'" << std::endl;
//     }
// }


void tenacitas::text_log_file::test1::run( ) {




  
    f6( );

    logger l_log;

    
    try {

        f3( );

        boost::thread l_th_1 ( f1 );

        f5( );
        
        boost::thread l_th_2 ( f2 );

        l_th_1.join( );

        f4( );

        l_th_2.join( );

        f7( );

        f12( );

        f14( l_log );

        // boost::thread l_th_14a ( f14, std::ref( l_log ) );

        log_info( l_log ) << "still breathing";

        //l_th_14a.join( );

        log_info( l_log ) << "still alive";
    }
    catch ( std::exception & l_ex ) {
        std::cout << "100: " << l_ex.what( ) << std::endl;
    }

    f8( );

    std::cout << "================ LEAVING ============" << std::endl;
    
}
